package com.code.leetcode.before50;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/21 21:08
 */
public class The38 {
    public String countAndSay(int n) {
        StringBuilder builder = new StringBuilder();
        int i = 1,p = 0;
        if (n == 1) return "1";
        String str = countAndSay(n - 1);
        for (i = 1; i < str.length(); i++) {
            if (str.charAt(p) != str.charAt(i)) {
                int count = i - p;
                builder.append(count).append(str.charAt(p));
                p = i;
            }
        }
        if (p != i) {
            builder.append(i - p).append(str.charAt(p));
        }
        return builder.toString();
    }
}
